package com.demo.controller;

import com.madgag.gif.fmsware.AnimatedGifEncoder;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.imageio.ImageIO;

public class GifDemo {

  public static void main(String[] args) throws Exception {
    BufferedImage image1 = ImageIO.read(new File(GifDemo.class.getResource("/images/1.jpg").getFile()));
    BufferedImage image2 = ImageIO.read(new File(GifDemo.class.getResource("/images/2.jpg").getFile()));
    BufferedImage image3 = ImageIO.read(new File(GifDemo.class.getResource("/images/3.jpg").getFile()));
    AnimatedGifEncoder e = new AnimatedGifEncoder();
    // 设置生成图片大小
    e.setSize(900, 1200);
    //生成的图片路径
    e.start(Files.newOutputStream(Paths.get("/Users/wangfengchen/Downloads/test/success.gif")));
    //图片之间间隔时间
    e.setDelay(1000);
    //重复次数 0表示无限重复 默认不重复
    e.setRepeat(0);
    //添加图片
    e.addFrame(image1);
    e.addFrame(image2);
    e.addFrame(image3);
    e.finish();
  }

}

